package com.yidu.hbats.action.emp;

import com.yidu.hbats.model.AtsEmpAthleteResults;
import com.yidu.hbats.service.emp.AtsEmpAthleteResultsService;
import com.yidu.utils.Message;
import com.yidu.utils.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: hbats
 * @description: 比赛成绩信息控制器
 * @author: 张超
 * @create: 2019-11-01 13:43
 */
@Controller
@RequestMapping("AtsEmpAthleteResultsController")
public class AtsEmpAthleteResultsController {

    /**
     * 比赛成绩信息接口
     */
    @Resource
    private AtsEmpAthleteResultsService atsEmpAthleteResultsService;

    /**
     * 新增或者修改
     * @param atsEmpAthleteResults
     * @return
     */
    @RequestMapping("insertOrUpdate")
    @ResponseBody
    public Message insertOrUpdate(AtsEmpAthleteResults atsEmpAthleteResults){

        if(atsEmpAthleteResults.getResultId()!=null){//有ID是修改

        }else{
            atsEmpAthleteResults.setIsva(1);//是否有效
            Date date = new Date();
            atsEmpAthleteResults.setCreatTime(date);//创建时间
        }


        atsEmpAthleteResultsService.saveOrUpdate(atsEmpAthleteResults);

        Message message = new Message();
        message.setNum(1);
        message.setMsg("编辑成功");
        return message;
    }

    /**
     * 根据id查找
     * @param id
     * @return
     */
    @RequestMapping("findById")
    @ResponseBody
    public AtsEmpAthleteResults findById(Integer id){
        return atsEmpAthleteResultsService.findById(id);
    }


    /**
     * 查询所有  返回map
     * @param atsEmpAthleteResults
     * @param page
     * @return
     */
    @RequestMapping("selectAll")
    @ResponseBody
    public Map selectAll(AtsEmpAthleteResults atsEmpAthleteResults, Page page){
        Map map = new HashMap();

        List<AtsEmpAthleteResults> list = atsEmpAthleteResultsService.selectAll(atsEmpAthleteResults,page);

        int count = atsEmpAthleteResultsService.selectCount(atsEmpAthleteResults);
        //int count = 10;
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", list);
        return map;
    }


    /**
     * 按id删除
     * @param id
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public Message delete(Integer id){
        Message message = new Message();
        if(id==null){
            message.setNum(0);
            message.setMsg("删除失败");
            return message;
        }else{
            AtsEmpAthleteResults atsEmpAthleteResults = new AtsEmpAthleteResults();
            atsEmpAthleteResults.setResultId(id);
            atsEmpAthleteResults.setIsva(2);
            atsEmpAthleteResultsService.saveOrUpdate(atsEmpAthleteResults);

            message.setNum(1);
            message.setMsg("删除成功");
            return message;
        }


    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("deleteAll")
    @ResponseBody
    public Message deleteAll(String ids){
        Message message = new Message();
        if(atsEmpAthleteResultsService.deleteAll(ids)==0){
            message.setNum(0);
            message.setMsg("删除失败");
        }else{
            message.setNum(1);
            message.setMsg("删除成功");
        }
        return message;
    }


    /**
     * 查询所有  返回list
     * @param atsEmpAthleteResults
     * @return
     */
    @RequestMapping("findAll")
    @ResponseBody
    public List<AtsEmpAthleteResults> findAll(AtsEmpAthleteResults atsEmpAthleteResults){
        return atsEmpAthleteResultsService.findAll(atsEmpAthleteResults);
    }

}